package com.chukun.netty.zerocopy;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
/**
 * @author chukun
 * new io服务端代码
 */
public class NewIOServer {

    public static void main(String[] args) throws IOException {

        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        ServerSocket sc = serverSocketChannel.socket();
        sc.bind(new InetSocketAddress(8899));
        ByteBuffer buffer = ByteBuffer.allocate(4096);
        while(true) {
            SocketChannel socketChannel = serverSocketChannel.accept();
            socketChannel.configureBlocking(true);
            int readCount = 0;
            while (readCount != -1) {
                readCount = socketChannel.read(buffer);
                buffer.rewind();
            }
        }
    }
}
